package com.office.shop.by.components;
import android.content.SharedPreferences;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class CAuth {

    private static String  auth_url = CConfig.serverUrl + "/android/auth";
    public static String Login = "";
    public static String Password ="";

    public static boolean login(String login,String pwd)
    {
      CAuth.Login = login;
      CAuth.Password = pwd;
      JSONObject jsonObject = CHttp.postJSON(auth_url, CAuth.getLogin());

      try {
          if(jsonObject != null)
             return jsonObject.getBoolean("auth");
          else
              return false;
        } catch (JSONException e) {
            e.printStackTrace();
        }

      return false;
    }

    public static List<NameValuePair> getLogin()
    {
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("login",  CAuth.Login));
        nameValuePairs.add(new BasicNameValuePair("password",CAuth.Password));
        return nameValuePairs;
    }



}
